/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Jiang Jinxi
 * Date: 2024-08-29
 * Time: 20:43
 */
class Counter{
    private int count;
    public void add(){
        count++;
    }
    public int get(){
        return count;
    }
}
public class Demo15 {
    public static void main(String[] args) {
        Counter counter1 = new Counter();
        Thread t1 = new Thread(() -> {
            for(int i = 0; i < 50000; i++){
                synchronized(counter1){
                    counter1.add();
                }
            }
        });
        Thread t2 = new Thread(() -> {
            for(int i = 0; i < 50000; i++){
                counter1.add();
            }
        });
        t1.start();

    }
}
